package com.novax.ex.activity.provider.controller;

import com.novax.ex.activity.open.api.RankStandingsApi;
import com.novax.ex.activity.open.model.query.RankStandingQuery;
import com.novax.ex.activity.open.model.response.RankStandingsResponse;
import com.novax.ex.activity.provider.service.RankStandingsService;
import com.novax.ex.common.results.ReturnResult;
import com.novax.ex.common.util.PageUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RestController;

import jakarta.annotation.Resource;
import java.util.Collections;

/**
 * @Description:
 * @Author: ChenXi
 * @Date:  2023/11/23 16:02
 **/
@Slf4j
@RestController
public class RankStandingsController extends BaseActivityController implements RankStandingsApi {

    @Resource
    private RankStandingsService rankStandingsService;

    @Override
    public ReturnResult<PageUtil<RankStandingsResponse>> page(RankStandingQuery rankStandingQuery) {
        PageUtil<RankStandingsResponse> page = new PageUtil<>(rankStandingQuery);
        page.setCondition(Collections.singletonMap("query", rankStandingQuery));
        rankStandingsService.findPage(page, RankStandingsResponse.class);
        page.getItems().forEach(item -> {
            String userId = item.getUserId();
            StringBuilder sb = new StringBuilder(userId);
            if(sb.length() >= 6){
                for (int i = 2; i < 6; i++) {
                    sb.setCharAt(i, '*');
                }
                item.setUserId(sb.toString());
            }

        });
        return ReturnResult.success(page);
    }

}
